package goleetcode

func firstDayBeenInAllRooms(nextVisit []int) int {
	mod := 1e9 + 7
	dp := make([]int, len(nextVisit))

	dp[0] = 2
	for i := 1; i < len(nextVisit); i++ {
		to := nextVisit[i]
		dp[i] = dp[i - 1] + 2
		if to != 0 {
			dp[i] = (dp[i] - dp[to - 1] + int(mod)) % int(mod)
		}
		dp[i] = (dp[i] + dp[i - 1]) % int(mod)
	}
	return dp[len(nextVisit) - 2]
}